<?php

require_once 'vendor/autoload.php';

// 加载Laravel应用
$app = require_once 'bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

echo "=== 检查权限服务 ===\n";

try {
    $service = app(\App\Services\PermissionService::class);

    // 测试所有权限
    echo "系统所有权限:\n";
    $allPermissions = $service->getAllPermissions();
    print_r($allPermissions);

    echo "\n权限总数: " . count($allPermissions) . "\n";

    // 检查是否包含管理权限
    echo "\n检查管理权限:\n";
    echo "user.manage: " . (in_array('user.manage', $allPermissions) ? '包含' : '不包含') . "\n";
    echo "employee.manage: " . (in_array('employee.manage', $allPermissions) ? '包含' : '不包含') . "\n";

    // 测试角色权限
    echo "\n超级管理员角色权限:\n";
    $rolePermissions = $service->getRolePermissions('super_admin');
    print_r($rolePermissions);

    echo "\n用户权限:\n";
    $user = \App\Models\User::find(1);
    $userPermissions = $service->getUserPermissions($user);
    print_r($userPermissions);

    echo "\n检查通配符权限:\n";
    echo "是否包含通配符: " . (in_array('*', $userPermissions) ? '是' : '否') . "\n";

    echo "\n检查具体权限:\n";
    echo "user.manage: " . ($service->hasPermission($user, 'user.manage') ? '有' : '无') . "\n";
    echo "employee.manage: " . ($service->hasPermission($user, 'employee.manage') ? '有' : '无') . "\n";

} catch (\Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
    echo "堆栈:\n" . $e->getTraceAsString() . "\n";
}
